<?PHP
$PurviewLevel=0;
require("../../inc/common.inc.php");
require_once(dirname(__FILE__)."/../"."Admin_ChkPurview.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link href="../images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php require("../mx_head.php");
if($actions=="delpic"){
	if(!$id){
		$fun->popmassage("请选择要删除的图片","","popback");
		exit();
	}
	$rsdb=$db->get_one("SELECT * FROM mx_sucai_msg WHERE mid='$id'");
	$pic=$db->get_one("select fpath from mx_sucai_file WHERE fid='$rsdb[mpic]'");
	if ($pic){@unlink("$webdb[updir]/$pic[fpath]");}
	//删除附件
	$db->excu("update mx_sucai_msg set mpic=0 WHERE mid='$id'");
	$url="sucai_text_edit.php?id=$id&mtype=".$rsdb["mtype"];
	jump2("操作成功",$url,1);
	exit();
}
?>
<?php
/**
*处理添加新消息
**/
if($action=="saveeidt"){

if ($mtitle=="" || empty($mtitle)){
	$fun->popmassage("请填写标题","","popback");
	exit();
}
if ($mcontent=="" || empty($mcontent)){
	$fun->popmassage("请填写正文","","popback");
	exit();
}
if ($mpic=="" || empty($mpic)){
	$fun->popmassage("必须插入一张图片","","popback");
	exit();
}

$truepath=preg_replace("/(.+)\/([^\/]+)\/([^\/]+)/is","\\1",'http://'.$HTTP_HOST.$PHP_SELF);
$mcontent=str_replace($truepath,"",$mcontent);
$mcontent=str_replace("﹪","%",$mcontent);
$edittime = mktime();
if($mabstract=="" || empty($mabstract)){$mabstract = DeleteHtml($mcontent);}
		
$db->excu("update`mx_sucai_msg` set `mtitle`='$mtitle', `mauthor`='$mauthor',`mabstract`='$mabstract',`mcontent`='$mcontent',`murl`='$murl', `mpic`='$mpic', `edittime`='$edittime',editid='".$_SESSION['mxadmin']['userid']."' where mid=$id");

jump2("操作成功","sucai_text.php",2);
exit();
}

	$rsdb=$db->get_one("SELECT * FROM mx_sucai_msg WHERE mid='$id' LIMIT 1");
    if ($rsdb=="" || empty($rsdb)){
	  $fun->popmassage("非法访问，系统将自动返回上一页！","","popback");
	  exit();
	}
	//获得封面图片
	$mpic = $db->getinfo("select fpath from mx_sucai_file where fid = ".$rsdb["mpic"]." limit 1");
	$mtype = $rsdb["mtype"];

    if ($gotourl==""){$gotourl=url_encode($_SERVER['HTTP_REFERER']);}
?>
	<!--right-->
	<div class="right">
	  <div class="gk">
			<div class="ti2 fl"><?php echo $mtype==1?"多图文消息":"单图文消息";?></div>
			<ul class="fr">
				<li><span class="c1"><?php echo $db->num_rows($db->excu("select mid from mx_sucai_msg where mtype=$mtype and fid=0"));?></span><span>信息总条数</span></li>
				<li class="line"></li>
				<li><span class="c2"><?php echo $db->num_rows($db->excu("select mid from mx_sucai_msg where mtype=$mtype and fid=0 and isok=0"));?></span><span>未审核条数</span></li>
				<li class="line"></li>
				<li><span class="c3"><?php echo $db->num_rows($db->excu("select mid from mx_sucai_msg where mtype=$mtype and fid=0 and isok=1"));?></span><span>已审核条数</span></li>
			</ul>
			<div class="clear"></div>
	  </div>
		<div class="height15"></div>
		<div class="xm2">
			<h1 class="fl"><?php echo $mtype==1?"多图文消息":"单图文消息";?></h1>
			<!--<span class="fr"><a href="#"><img src="../images/right_4.png" alt="设置" /></a></span>-->
			<div class="clear"></div>
		</div>
		<div class="xm2_b">
		  
			<div class="height15"></div>
				<script type="text/javascript" src="../js/jquerys-1.5.1.js"></script>
				<script language="javascript">
				$(document).ready(function(){ //这个就是传说的ready   
				$(".stripe tr").mouseover(function(){   
				//如果鼠标移到class为stripe的表格的tr上时，执行函数   
				$(this).addClass("over");}).mouseout(function(){   
				//给这行添加class值为over，并且当鼠标一出该行时执行函数   
				$(this).removeClass("over");}) //移除该行的class   
				$(".stripe tr:even").addClass("alt");   
				//给class为stripe的表格的偶数行添加class值为alt
				//www.divcss5.com 整理特效
				});  
				function showimg(fid,fsrc,label){
					document.getElementById(label).value=fid;
					document.getElementById(label+"3").src=fsrc;
					document.getElementById(label+"2").style.display="block";
					document.getElementById("msgshowpic").src=fsrc;
				}
				function reurl(url,name,size,p){
					document.location=document.location;
				}
				function showtr(trid){
					document.getElementById(trid+"2").style.display="block";
					document.getElementById(trid+"1").style.display="none";
				} 
				function checkform(){
					var mtitle,mpic,mcontent;
					mtitle = document.form2.mtitle.value;
					mpic = document.form2.mpic.value;
					mcontent = document.form2.mcontent.value;
					if(mtitle==""||mtitle.length>64){
						alert("标题不能为空且长度不能超过64个字");
						document.form2.mtitle.focus();
						return false;
					}
					
					if(mcontent==""||mcontent.length>20000){
						alert("正文不能为空且长度不能超过20000个字");
						document.form2.mcontent.focus();
						return false;
					}
					if(mpic==""){
						alert("必须插入一张图片");
						return false;
					}
					return true;
			    }
				var xmlobj; //定义XMLHttpRequest对象
				function CreateXMLHttpRequest()
				{
				if(window.XMLHttpRequest)
				{//Mozilla浏览器
				xmlobj=new XMLHttpRequest();
				if(xmlobj.overrideMimeType)
				{//设置MIME类别
				xmlobj.overrideMimeType("text/xml");
				}
				}
				else if(window.ActiveXObject)
				{ //IE浏览器
				try
				{
				xmlobj=new ActiveXObject("Msxml2.XMLHttp");
				}
				catch(e)
				{
				try
				{
				xmlobj=new ActiveXobject("Microsoft.XMLHttp");
				}
				catch(e)
				{
				}
				}
				}
				
				}
				function delpic(){
					CreateXMLHttpRequest(); 
					fid = document.form2.mpic.value;
					var showurl = "delpic.php?fid="+fid; 
					xmlobj.open("GET", showurl, true);
					xmlobj.onreadystatechange = after_delpic; 
					xmlobj.send(null); 
				}
				function after_delpic() { //用于处理状态的函数
				if(xmlobj.readyState == 4 && xmlobj.status == 200) //如果URL成功访问，则输出网页 
				{	
					ss=xmlobj.responseText;
					if (ss=="1"){
						document.getElementById("mpic").value="";
						document.getElementById("mpic3").src="";
						document.getElementById("mpic2").style.display="none";	
						document.getElementById("msgshowpic").src="../images/nopic.jpg";
					}else{
						alert("参数错误");
					}
				}
				}
				function msgshow(val,showid,rval){
					if(val==""){val=rval}
					document.getElementById(showid).innerHTML=val;
				}
				</script>
                <div class="addleft">
                 <?php if($mtype==0){?>
				<div class="msgshow">
            	<div class="imgitem11">
                	<div class="imgitemtop11"></div>
                    <div class="imgitembod11">
                    	<div class="imgitembod-txt11">
                            <h1 id="msgshowtitle"><?php echo $rsdb["mtitle"]?></h1>
                            <span><?php echo date("Y-m-d",$rsdb["addtime"])?></span>
                        </div>
                        <div class="imgitembod-img11"><img src="<?php echo $mpic["fpath"];?>" width="300" height="166" id="msgshowpic" /></div>
                        <div class="imgitembod-txt11">
                            <span id="msgshowcon"><?php echo $rsdb["mabstract"];?></span>
                        </div>
                    </div>
                    <div class="imgitembot11"></div>
                </div>
                
                <div class="clear"></div>
            </div>
				<?php
				 }else{
                if(intval($rsdb["fid"])!=0){
					$fid = $rsdb["fid"];
					$fmsginfo = $db->getinfo("select * from mx_sucai_msg where mid='$fid'");
					if($fmsginfo){
						$fmsgpic = $db->getinfo("select * from mx_sucai_file where fid='".$fmsginfo["mpic"]."'");
					}
				}else{
					$fid = $rsdb["mid"];
					$fmsginfo = $db->getinfo("select * from mx_sucai_msg where mid='$fid'");
					if($fmsginfo){
						$fmsgpic = $db->getinfo("select * from mx_sucai_file where fid='".$fmsginfo["mpic"]."'");
					}
				}
				?>
                	<div class="msgshow">
            	<div class="imgitem11">
                	<div class="imgitemtop11"></div>
                    <div class="imgitembod11">
                    	<div class="imgitembod-txt11">
                            <span><?php echo date("Y-m-d")?></span>
                        </div>
                        <div class="imgitembod-img11"><img src="<?php echo $fmsgpic?$fmsgpic["fpath"]:"../images/nopic.jpg";?>" width="300" height="166" <?php echo intval($rsdb["fid"])!=0?'':'id="msgshowpic"';?> />
                        <div class="msgshowtitle11" <?php echo intval($rsdb["fid"])!=0?'':'id="msgshowtitle"';?>><?php echo $fmsginfo?$fmsginfo["mtitle"]:"标题";?></div>
                        </div>
                        <div class="imgitembod-txt11">
                            <span id="msgshowcon"></span>
                        </div>
                    </div>
                    <?php
					if(intval($fid)!=0){
						$sonmsgquery = $db->excu("select * from mx_sucai_msg where fid='$fid'");	
						$sonmsginfo = array();
						while($sonmsgarr = $db->fetch_array($sonmsgquery)){
							$sonmsginfo[]=$sonmsgarr;
						}
						if(count($sonmsginfo)>0){
							foreach($sonmsginfo as $key =>$value){
							$sonmsgpic = $db->getinfo("select * from mx_sucai_file where fid='".$value["mpic"]."'");
					?>
                    <div class="imgitembod22">
                        <div class="imgitembod-sonmsg" <?php if(intval($id)!=intval($value["mid"])){?>onmouseover="document.getElementById('edit<?php echo $value["mid"];?>').style.display='block';" onmouseout="document.getElementById('edit<?php echo $value["mid"];?>').style.display='none';"<?php }?>>
                        	<div class="imgitembod-sonmsg11"><img src="<?php echo $sonmsgpic["fpath"];?>" width="73" height="73" <?php echo intval($id)!=intval($value["mid"])?'':'id="msgshowpic"';?> /></div>
                            <div class="imgitembod-sonmsg22"><h1  <?php echo intval($id)!=intval($value["mid"])?'':'id="msgshowtitle"';?>><?php echo $value["mtitle"];?></h1></div>
                            <?php if(intval($id)!=intval($value["mid"])){?>
                            <div class="msgshowedit" id="edit<?php echo $value["mid"];?>" style="display:none;"><a href="sucai_text_edit.php?id=<?php echo $value["mid"];?>">编辑</a>&nbsp;&nbsp;<a href="sucai_text.php?action=work&jobs=delete&id=<?php echo $value["mid"]?><?php echo $poststr;?>" onClick="return confirm('删除后不可恢复,你确实要删除吗?')">删除</a></div>
                            <?php
                            }?>
                        </div>
                    </div>
                    <?php
							}
						}
					?>
                    <?php
					}
				 
					?>
                    <div class="imgitembot11"></div>
                </div>
                
                <div class="clear"></div>
            </div>
            <?php }?>
                </div>
                <div class="addright">
				<form id="form2" name="form2" method="post" action="sucai_text_edit.php?action=saveeidt" onsubmit="return checkform()">
                <input type="hidden" name="id" value="<?php echo $id;?>">
				  <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="60" align="right" class="font14">标题：</td>
                      <td colspan="2"><input type="text" name="mtitle" size="50" value="<?php echo $rsdb["mtitle"]?>" onkeyup="msgshow(this.value,'msgshowtitle','标题')" maxlength="50" /></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">作者：</td>
                      <td colspan="2"><input type="text" name="mauthor" size="50" value="<?php echo $rsdb["mauthor"]?>" /></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14"> 封面：</td>
                      <td width="100">
                      <input type='hidden' name='mpic' class="input2" id="mpic" value="<?php echo $rsdb["mpic"]?>">
                      <button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:415px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=2&formId=1&fn=showimg&dir=sucai&label=mpic"></iframe>
                      </td>
                      <td class="font12"><?php echo $rsdb["fid"]!=0?"小图片建议尺寸：400像素 * 400像素":"大图片建议尺寸：720像素 * 400像素";?></td>
                    </tr>
                    
                    <tr>
                      <td align="right" class="font14"></td>
                      <td colspan="2">
                      <div id="mpic2">
                      <img src="<?php echo $mpic["fpath"];?>" width="100" id="mpic3" />&nbsp;<!--<a href="javascript:void(0)" style="color:#F00" onclick="delpic()">取消</a>-->
                      </div>
                      </td>
                    </tr>
                    <?php if($mtype==0){?>
                    <tr>
                      <td colspan="3">
                    <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="53" align="right" class="font14">摘要：</td>
                      <td colspan="2"><textarea name="mabstract"  cols="60" rows="5" onkeyup="msgshow(this.value,'msgshowcon','')"><?php echo $rsdb["mabstract"];?></textarea></td>
                    </tr>
                    </table>
                    </td>
                    </tr>
                    <?php
					}
					?>
                    <tr>
                      <td align="right" class="font14">正文：</td>
                      <td colspan="2">
                      <script charset="utf-8" src="/webedito/kindeditor-min.js"></script>
					  <script charset="utf-8" src="/webedito/lang/zh_CN.js"></script>
                      <script>
                      var editor;
                      KindEditor.ready(function(K) {
                          editor = K.create('textarea[id="content"]', {
                            allowFileManager : true,
                            filterMode : false,
                            afterBlur : function() {this.sync();},

						items : ['bold','italic', 'underline', '|','insertorderedlist','insertunorderedlist','|','image','|','removeformat','forecolor','hilitecolor']
                          });
                      });
                      </script>
                      <textarea name="mcontent" id="content" style="width:460px;height:300px;visibility:hidden;display:none;"><?php echo $rsdb["mcontent"];?></textarea>
                      </td>
                    </tr>
                    
                    <tr>
                      <td colspan="3">
                    <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="53" align="right" class="font14">链接：</td>
                      <td colspan="2"><input type="text" name="murl" size="50" value="<?php echo $rsdb["murl"]?>" /></td>
                    </tr>
                    </table>
                    </td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td class="font14" colspan="2"><input type="submit" class="button" name="button" id="button" value="完成" />&nbsp;&nbsp;
                      <input type="reset" class="button2" name="button2" id="button2" value="取消" /></td>
                    </tr>
                    <tr>
                      <td colspan="3" height="20">&nbsp;</td>
                    </tr>
                  </table>
          </form>
          </div>
          <div class="clear"></div>
				<div class="height15"></div>
	  </div>
		<div class="clear"></div>
		<div class="height15"></div>
       
	  </div>
		<div class="clear"></div>
  <?php require("../mx_foot.php") ;?>
  </div>
	<!--right-end-->
</body>
</html>
